#include "linux/prosser.h"
#include "linux/string.h"
#include "asm/thread_info.h"
#include "asm/processor.h"
#include "linux/current.h"

void ret_from_fork(void) __asm__("ret_from_fork");

int copy_thread(int nr, unsigned long clone_flags, unsigned long stack_start, unsigned long stack_size, struct task_struct *p, struct pt_regs *regs)
{
    struct thread_info *thread = task_thread_info(p);
    struct pt_regs *childregs = task_pt_regs(p);


    memset(&thread->cpu_context, 0, sizeof (struct cpu_context_save));
    if (!(p->flags & PF_KTHREAD))
    {
        *childregs = *current_pt_regs();
        childregs->ARM_r0 = 0;
    }
    else
    {
        thread->cpu_context.r4 = stack_size;
        thread->cpu_context.r5 = stack_start;
    }
    
    thread->cpu_context.pc = (unsigned long)ret_from_fork;
    thread->cpu_context.sp = (unsigned long)childregs;


    return 0;
}
